package cn.szq.springframework.context.annotation;

import cn.hutool.core.util.ClassUtil;
import cn.szq.springframework.beans.factory.config.BeanDefinition;
import cn.szq.springframework.stereotype.Component;
import org.openjdk.jol.util.ClassUtils;

import java.util.LinkedHashSet;
import java.util.Set;

/**
 * @ClassName: ClassPathScanningCandidateComponentProvider
 * @Description:
 * @Author: szq
 * @Date: 2021-09-18 16:06:08
 */
public class ClassPathScanningCandidateComponentProvider {

    public Set<BeanDefinition> findCandidateComponents(String basePackage){
        Set<BeanDefinition> candidates = new LinkedHashSet<>();
        Set<Class<?>> classes = ClassUtil.scanPackageByAnnotation(basePackage, Component.class);
        for(Class<?> clazz : classes){
            candidates.add(new BeanDefinition(clazz));
        }
        return candidates;
    }
}
